package com.hl.widget;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hl.R;
import com.hl.ui.MainActivity;
import com.hl.ui.StartActivity;
import com.hl.ui.WellcomeActivity;

public class CreateViews {

	/**
	 * ������Ʒview
	 * 
	 * @param name
	 * @param count
	 * @param price
	 * @return
	 */
	public static View onCreateView(Context context,String name, String count, String price,String msg,String taget) {
		LinearLayout layout = new LinearLayout(context);
		TextView dishesName = new TextView(context);
		TextView dishesCount = new TextView(context);
		TextView dishesPrice = new TextView(context);

		LayoutParams group = new LayoutParams(LayoutParams.MATCH_PARENT,
				LayoutParams.WRAP_CONTENT);
		LayoutParams child = new LayoutParams(0, LayoutParams.WRAP_CONTENT, 1);
		layout.setLayoutParams(group);
		layout.setOrientation(LinearLayout.HORIZONTAL);
		dishesCount.setLayoutParams(child);
		dishesCount.setGravity(Gravity.LEFT);
		dishesName.setLayoutParams(child);
		dishesPrice.setLayoutParams(child);

		dishesCount.setTextColor(context.getResources().getColor(R.color.dishes_text_color));
		dishesName.setTextColor(context.getResources().getColor(R.color.dishes_text_color));
		dishesPrice.setTextColor(Color.RED);

		dishesCount.setText(count);
		dishesName.setText(name);
		dishesPrice.setText(price);

		layout.addView(dishesName);
		layout.addView(dishesCount);
		layout.addView(dishesPrice);
		
		return layout;
	}
	public static TextView oncreateTextView(Context context,String s){
		TextView view=new TextView(context);
	    view.setLayoutParams(new LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
	    view.setTextSize(12);
	    view.setText(s);
		return view;
	}
	/**
	 * Guide of a page
	 * @param context
	 * @param index
	 * @return View
	 */
	public View onCreateViews(Context context,int index) {
		final WellcomeActivity contexts=(WellcomeActivity) context;
		View view = LayoutInflater.from(context).inflate(
				R.layout.item_wellcome_viewpage, null);
		ImageView page1=(ImageView)view.findViewById(R.id.wellcome_viewpage_current1);
		ImageView page2=(ImageView)view.findViewById(R.id.wellcome_viewpage_current2);
		ImageView page3=(ImageView)view.findViewById(R.id.wellcome_viewpage_current3);
		ImageView page4=(ImageView)view.findViewById(R.id.wellcome_viewpage_current4);
		ImageView button=(ImageView)view.findViewById(R.id.wellcome_viewpage_button);
		RelativeLayout relative=(RelativeLayout)view.findViewById(R.id.wellcome_layout);
		if(index==1){
			relative.setBackgroundResource(R.drawable.wellcome_image_page1);
			button.setVisibility(View.INVISIBLE);
			page1.setBackgroundResource(R.drawable.wellcome_image_check);
		}else if(index==2){
			relative.setBackgroundResource(R.drawable.wellcome_image_page2);
			button.setVisibility(View.INVISIBLE);
			page2.setBackgroundResource(R.drawable.wellcome_image_check);
		}else if(index==3){
			relative.setBackgroundResource(R.drawable.wellcome_image_page3);
			button.setVisibility(View.INVISIBLE);
			page3.setBackgroundResource(R.drawable.wellcome_image_check);
		}else if(index==4){
			relative.setBackgroundResource(R.drawable.wellcome_image_page4);
			button.setVisibility(View.VISIBLE);
			page4.setBackgroundResource(R.drawable.wellcome_image_check);
			button.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					Intent intent=new Intent(contexts,StartActivity.class);
					contexts.startActivity(intent);
					contexts.finish();
				}
			});
		}
		return view;
	}
}
